<?php
/**
 * Author:xsc
 * Time:2023/8/31 19:11
 */

namespace App\Http\Controllers\Common;

use App\Common\ResponseCode;
use App\Http\Controllers\BaseController;
use App\Params\Common\SpecialDeleteParams;
use App\Params\Common\SpecialEditParams;
use App\Params\Common\SpecialEditStatusParams;
use App\Service\Common\SpecialService;
use App\Params\Common\SpecialCreateParams;
use App\Params\Common\SpecialDetailParams;
use App\Params\Common\SpecialPrivilegeParams;
use App\Params\Common\SpecialSendParams;

class SpecialController extends BaseController
{

    /**
     * 新增/更新藏品
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException|\OSS\Core\OssException
     * Author:xsc
     * Time:2023/9/5 10:40
     */
    public function create()
    {
        $special_id = request("special_id");
        if (empty($special_id)) {
            $params = SpecialCreateParams::create();
            $data = SpecialService::getInstance()->create($params);
        } else {
            $params = SpecialEditParams::create();
            $data = SpecialService::getInstance()->edit($params);
        }

        return $this->success($data);
    }

    /**
     * 藏品详情
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     * Author:xsc
     * Time:2023/9/5 10:13
     */
    public function detail()
    {
        $params = SpecialDetailParams::create();
        $data = SpecialService::getInstance()->detail($params);
        return $this->success($data);
    }

    /**
     * 藏品赋能
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     * Author:xsc
     * Time:2023/9/4 19:39
     */
    public function privilege()
    {
        $params = SpecialPrivilegeParams::create();
        $data = SpecialService::getInstance()->privilege($params);
        return $this->success($data);
    }

    /**
     * 发放藏品
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     * @throws \RedisException
     * Author:xsc
     * Time:2023/9/20 14:22
     */
    public function send()
    {
        $params = SpecialSendParams::create();
        $data = SpecialService::getInstance()->send($params);
        return $this->success($data);
    }

    /**
     *  编辑藏品上下架状态
     * @throws \App\Exceptions\BusinessException
     */
    public function editSpecialStatus(): \Illuminate\Http\JsonResponse
    {
        $param = SpecialEditStatusParams::create();
        $ret = SpecialService::getInstance()->editSpecialStatus($param);
        if ($ret)
            return $this->success();
        return $this->fail(ResponseCode::FAIL);
    }

    /**
     *  删除藏品
     * @throws \App\Exceptions\BusinessException
     */
    public function deleteSpecial()
    {
        $param = SpecialDeleteParams::create();
        $res = SpecialService::getInstance()->deleteSpecial($param);
        if ($res)
            return $this->success();
        return $this->fail(ResponseCode::FAIL);
    }
}
